package io.gitee.kotle.player.core.helper

import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.LifecycleOwner
import io.gitee.kotle.player.core.IPlayer

/**
 *
 * 描述：自动暂停和销毁播放器
 *
 * 创建人：jiale.wei
 * 创建时间：2023/4/20 23:19
 *
 */
open class PlayerBindLifecycleHelper<Media, Model : IPlayer.IModel<Media>>(
    val player: IPlayer<Media, Model>,
) : LifecycleEventObserver {
    override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) {
        when (event) {
            Lifecycle.Event.ON_CREATE -> {

            }

            Lifecycle.Event.ON_START -> {

            }

            Lifecycle.Event.ON_RESUME -> {

            }

            Lifecycle.Event.ON_PAUSE -> {

            }

            Lifecycle.Event.ON_STOP -> {
                player.pause()
            }

            Lifecycle.Event.ON_DESTROY -> {
                player.release()
            }

            Lifecycle.Event.ON_ANY -> {

            }
        }
    }
}